class Solution {
public:
    int minOperations(vector<int>& nums, int x) {
         int len = nums.size();
         int sum=0;
         for(int i=0;i<len;i++)
         {
             sum+=nums[i];
         }
         int target = sum-x;
         if(target<0)
            return -1;
        int ret=-1;
         for(int left=0,right=0,tam=0;right<len;right++)
         {
             tam+=nums[right];
             while(tam>target)
                tam-=nums[left++];
             if(tam == target)
             {
                 ret = max(ret,right-left+1);
             }
         }
        if(ret==-1) return -1;
        else return len-ret;
    }
};